package request2_p2p;

import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) {

        Merchant KFC=new Merchant(1,"肯德基一店",new int[]{1,2});
        Merchant McDonald=new Merchant(2,"麦当劳",new int[]{2,4});
        Merchant Dicos=new Merchant(3,"德克士",new int[]{3,5});
        Merchant KFC1=new Merchant(1,"肯德基二店",new int[]{4,4});
        Merchant McDonald1=new Merchant(2,"麦当劳二店",new int[]{5,5});
        Merchant Dicos1=new Merchant(3,"德克士二店",new int[]{6,6});
        List<Merchant> KFCs=new ArrayList<>();
        KFCs.add(KFC); KFCs.add(KFC1);
        List<Merchant> Dicoss=new ArrayList<>();
        Dicoss.add(Dicos);Dicoss.add(Dicos1);
        List<Merchant> McDonalds=new ArrayList<>();
        McDonalds.add(McDonald);McDonalds.add(McDonald1);

        Consumer c1=new Consumer(1,"小明",new int[]{7,7});
        Consumer c2=new Consumer(2,"小华",new int[]{8,8});
        Consumer c3=new Consumer(3,"小丽",new int[]{9,9});

        Product p1=new Product(1,"香辣鸡腿堡",KFC);
        Product p2=new Product(1,"老北京鸡肉卷",KFC);
        Product p3=new Product(2,"麦香鸡",McDonald);
        Product p4=new Product(1,"麦香鱼",McDonald);
        Product p5=new Product(3,"炸鸡",Dicos);
        Product p6=new Product(1,"卡布奇诺",Dicos);



        List<Product> l1=new ArrayList<>();
        List<Product> l2=new ArrayList<>();
        List<Product> l3=new ArrayList<>();

        l1.add(p1);l1.add(p2);
        l2.add(p3);l2.add(p4);
        l3.add(p5);l3.add(p6);

        COrderEvent co1=new COrderEvent(l1,c1,KFC);
        COrderEvent co2=new COrderEvent(l2,c2,McDonald);
        COrderEvent co3=new COrderEvent(l3,c3,Dicos);

        COrderSubscriber corderSubscriber=new COrderSubscriber(KFCs);
        COrderPublisher cp1=new COrderPublisher(c1);
        cp1.addObserver(corderSubscriber);
        cp1.dispatch(co1);


        MOrderPublisher kfcDispatch=new MOrderPublisher(KFC);
        MOrderPublisher mcDonaldDispatch=new MOrderPublisher(McDonald);
        MOrderPublisher dicosDispatch=new MOrderPublisher(Dicos);

        MOrderPublisher kfcDispatch1=new MOrderPublisher(KFC1);
        MOrderPublisher mcDonaldDispatch1=new MOrderPublisher(McDonald1);
        MOrderPublisher dicosDispatch1=new MOrderPublisher(Dicos1);
        List<MOrderPublisher> mOrderPublishers=new ArrayList<>();
        mOrderPublishers.add(kfcDispatch);  mOrderPublishers.add(kfcDispatch1);
        mOrderPublishers.add(mcDonaldDispatch);  mOrderPublishers.add(mcDonaldDispatch1);
        mOrderPublishers.add(dicosDispatch);  mOrderPublishers.add(dicosDispatch1);

        Rider r1=new Rider(1,"张三",new int[]{3,5});
        Rider r2=new Rider(2,"李四",new int[]{4,3});
        Rider r3=new Rider(3,"王五",new int[]{2,6});
        List<Rider> subscriberList=new ArrayList<>();
        subscriberList.add(r1);
        subscriberList.add(r2);
        subscriberList.add(r3);
        MOrderSubscriber morderSubscriber=new MOrderSubscriber(subscriberList);
        //注册事件监听器
        kfcDispatch.addObserver(morderSubscriber);
        mcDonaldDispatch.addObserver(morderSubscriber);
        dicosDispatch.addObserver(morderSubscriber);
        kfcDispatch1.addObserver(morderSubscriber);
        mcDonaldDispatch1.addObserver(morderSubscriber);
        dicosDispatch1.addObserver(morderSubscriber);

        //产生kfc订单
//        kfcDispatch.dispatch("test");
        for(MOrderPublisher m:mOrderPublishers){
            if(m.getMerchant().getName()==co1.getMerchant().getName()){
                m.dispatch(co1);
            }
        }

    }
}
